package servlet;

import model.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DeleteServlet",urlPatterns = "/DeleteServlet")
public class DeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id=request.getParameter("id");
        User user=new User(id, null, null, null, null, null);
        UserService userService=new UserService();
        boolean b = userService.userDeleteService(user);
        if(b){
            List<User> userList=userService.userQueryAllService();

            request.getSession().setAttribute("userList",userList);
            response.sendRedirect("main.jsp");
        }else {
            System.out.println("删除失败");
            request.getSession().setAttribute("errorDelete","删除失败");
            response.sendRedirect("delete.jsp");
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request,response);
    }
}
